home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
EDITOR
/
KDP32_1.ARJ
/
K24.C
< prev
next >
Wrap
Text File
|
1992-05-20
|
6KB
|
284 lines
/*K24.C
FONT EDITOR FOR 24-DOT FONT FILES
J.W. Stumpel, Tokyo, February 1992 */
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>
#define F1 0x3b
#define F2 0x3c
#define F3 0x3d
#define R_ARROW 0x4d
#define L_ARROW 0x4b
#define UP_ARROW 0x48
#define DN_ARROW 0x50
#define SPBAR 0x39
#define ESC 0x01
#define xstart 15 /*coordinates of left top*/
#define ystart 4 /*of kanji display*/
#define CURSOROFF cursor(40,40)
#define CURSORON cursor(6,7)
#define byte unsigned char
#define word unsigned int
#define HIGHLIGHT 0x1e /*Yellow on blue; attr of header & footer line*/
byte kanji_attr[6]={0x1E,0x3E,0x1E,0x3E,0x1E,0x3E};
typedef struct {
byte b[24][3];
} kanji;
int maxrow=83;
byte mask[8]={128,64,32,16,8,4,2,1};
kanji charbuf; /*buffer for one character. For copying.*/
kanji thiskanji; /*kanji being edited*/
byte far *keybyte=MK_FP(0x40,0x17); /*PC keyboard status byte*/
FILE *fp;
char *instr[5]= { "SPACE change pixel",
"F1 put char in buffer",
"F2 copy buffer to char",
"F3 save this char to disk",
"ESC exit"};
void paint_character (int,int);
void symbol(int x, int y);
void cursor(int start, int end);
void movecursor(int x,int y);
char getkey(int *k);
void doexit (char *s,int endcode);
void initialize(char *);
void showhex(int y);
word sjis(int ku, int ten);
void beep(void);
void erbar(char *);
void readkanji(int,int);
void savekanji(int,int);
char * usage= "Font editor for 24 x 24 JIS files"
"\nUsage: K24 <fontfilename>";
main(int argc,char *argv[])
{
int x=0,y=0,i,j,k;
int ku=1,ten=1;
if (argc!=2) {
printf("%s",usage);
exit(1);
}
initialize(argv[1]);
textattr(HIGHLIGHT);
readkanji(ku,ten);
paint_character(ku,ten);
do {
movecursor(x,y);
getkey(&k);
if(*keybyte&3) /*test for left or right shift pressed*/
{
switch(k)
{
case L_ARROW: if (ten==1) ten=95; ten--; break;
case R_ARROW: if (ten==94) ten=0; ten++; break;
case UP_ARROW: if (ku>1) ku--; break;
case DN_ARROW: if (ku<maxrow) ku++; break;
}
readkanji(ku,ten);
paint_character(ku,ten);
}
else switch(k)
{
case L_ARROW: if (x>0) x--; break;
case R_ARROW: if (x<23) x++; break;
case UP_ARROW: if (y>0) y--; break;
case DN_ARROW: if (y<23) y++; break;
case SPBAR: thiskanji.b[y][x/8] ^=mask[x&7];
symbol(x,y);
showhex(y);
break;
case F1: for (j=0;j<24;j++)
for (i=0;i<3;i++)
charbuf.b[j][i]=thiskanji.b[j][i];
beep();
break;
case F2: for (j=0;j<24;j++)
for (i=0;i<3;i++)
thiskanji.b[j][i]=charbuf.b[j][i];
paint_character(ku,ten);
beep();
break;
case F3: savekanji(ku,ten);
beep();
break;
}
}
while (k!=ESC);
if (fclose(fp)) erbar ("Error closing file!");
doexit("",0);
}
void erbar(char *s)
/*display red error bar with message. User must type ESC*/
{
int k;
beep();
textattr(0xcf);
gotoxy(40,14);
cprintf(s);
while (getkey(&k)!=0x1b);
textattr(0x7);
gotoxy(40,14);
cprintf(" "); /*erase error bar*/
}
void initialize(char *filename)
{
int j;
fp=fopen(filename,"r+b");
if (!fp) erbar("Error opening file");
textattr(7);
clrscr();
CURSOROFF;
textattr(HIGHLIGHT);
gotoxy(1,1);
cprintf( " 24x24 dot Kanji"
" Font Editor ");
gotoxy(1,25);
cprintf( " Arrows: move around in image "
" Shift-arrows: move around in table");
textattr(7);
gotoxy(xstart+24,ystart-1);
cprintf(" (top) (bottom)");
for (j=0;j<5;j++) {
gotoxy(20,19+j);
cprintf(instr[j]);
}
}
void doexit (char *s,int endcode)
/* To finish the program neatly*/
{
window(1,1,80,25);
textattr(7);
clrscr();
cprintf(s); /*print a sign-off message*/
CURSORON;
exit(endcode); /*code accessible from batch files*/
}
char getkey(int *k)
/*Reads the next key in the keyboard buffer and returns it in
the argument k. */
{
_AH=0;
geninterrupt(0x16);
_CX=_AX; /*turns out to be necessary*/
*k=_AH;
return (_CL);
}
void beep(void)
{
sound(2400);
delay(50);
nosound();
}
void cursor(int start, int end)
{
_AH=1;
_CH=start;
_CL=end;
geninterrupt(0x10);
}
void showhex(int y)
{
y&=0xFFFE;
gotoxy(xstart+26,y/2+ystart);
textattr(0x3E);
cprintf("%02X%02X%02X %02X%02X%02X",thiskanji.b[y][0],
thiskanji.b[y][1],
thiskanji.b[y][2],
thiskanji.b[y+1][0],
thiskanji.b[y+1][1],
thiskanji.b[y+1][2]);
}
void symbol(int x, int y)
{
int top,bottom;
y/=2;
/*determine value of two pixels at the same time*/
top =((thiskanji.b[2*y][x/8]&mask[x&7])!=0)? 1:0;
bottom =((thiskanji.b[2*y+1][x/8]&mask[x&7])!=0)? 1:0;
gotoxy(x+xstart,y+ystart);
textattr (kanji_attr[x/4]);
switch(top+2*bottom)
{
case 0: putch(' '); break;
case 1: putch(223); break;
case 2: putch(220); break;
case 3: putch(219); break;
}
}
void paint_character (int ku, int ten)
{
int x,y;
CURSOROFF;
for (y=0;y<24;y+=2)
{
for (x=0;x<24;x++) symbol(x,y);
showhex(y);
}
gotoxy(23,16);
textattr(7);
cprintf("ku=%2u, ten=%2u (sjis: %4X)",ku,ten,sjis(ku,ten));
}
word sjis(int ku, int ten)
{
word high,low;
high=0x80+(ku+1)/2 ; /* 2 ku values share the same high byte. */
if (high>0x9F) high+=0x40; /* if outside 81-9F range, lift to E0-EA range*/
if (ku&1) { /* ku is odd*/
low= 0x3F+ten;
if (low>=0x7F) low++;
}
else low= 0x9E+ten; /* ku is even */
return (256*high+low);
}
void movecursor (int x,int y)
{
gotoxy(x+xstart,y/2+ystart);
if (y&1) cursor(5,8); /*bottom half*/
else cursor(1,4); /*top half*/
}
void readkanji(int ku, int ten)
{
fseek(fp,(long)sizeof(kanji)*((ku-1)*94+ten-1),SEEK_SET);
if (fread(&thiskanji,sizeof(kanji),1,fp)!=1)
erbar("Read error!");
}
void savekanji(int ku,int ten)
{
fseek(fp,(long)sizeof(kanji)*((ku-1)*94+ten-1),SEEK_SET);
if (fwrite(&thiskanji,sizeof(kanji),1,fp)!=1)
erbar("Write error!");
}